<?php

use App\Http\Controllers\Admin\Goods\CategoryController as ShopCategoryController;
use App\Http\Controllers\Admin\Goods\GoodsController;
use App\Http\Controllers\Admin\Message\MessageController;
use App\Http\Controllers\Admin\Order\ShopOrderController;
use App\Http\Controllers\Admin\Order\SponsorOrderController;
use App\Http\Controllers\Admin\Other\AliYunCloudController;
use App\Http\Controllers\Admin\Other\SettingController;
use App\Http\Controllers\Admin\Ranch\ApplyController;
use App\Http\Controllers\Admin\Ranch\RanchController;
use App\Http\Controllers\Admin\Sponsor\CategoryController as SponsorCategoryController;
use App\Http\Controllers\Admin\Sponsor\ExpressController;
use App\Http\Controllers\Admin\Sponsor\SlaughterController;
use App\Http\Controllers\Admin\Sponsor\SponsorController;
use App\Http\Controllers\Admin\Sponsor\SponsorGoodsController;
use App\Http\Controllers\Admin\Sponsor\UserIntegralController;
use App\Http\Controllers\Admin\SuperAdmin\ApiController;
use App\Http\Controllers\Admin\SuperAdmin\AuthorityController;
use App\Http\Controllers\Admin\SuperAdmin\LoginController;
use App\Http\Controllers\Admin\SuperAdmin\MenuController;
use App\Http\Controllers\Admin\SuperAdmin\UserController as AdminUserController;
use App\Http\Controllers\Admin\User\UserController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::group(['prefix' => 'sysUser', 'namespace' => 'User'], function () {
    Route::post('login', [LoginController::class, 'login']);     // 登录
    Route::post('captcha', [LoginController::class, 'captcha']); // 验证码

    Route::group(['middleware' => 'adminAuth'], function () {
        Route::post('logout', [LoginController::class, 'logout']);                     // 退出登录
        Route::get('userInfo', [AdminUserController::class, 'userInfo']);              // 用户详情
        Route::post('setSelfInfo', [AdminUserController::class, 'setSelfInfo']);       // 设置自身信息
        Route::post('changePassword', [AdminUserController::class, 'changePassword']); // 修改密码
    });
});


// 超级管理员
Route::group(['prefix' => 'superAdmin', 'namespace' => 'SuperAdmin'], function () {
    // 菜单
    Route::group(['prefix' => 'menu', 'middleware' => 'adminAuth'], function () {
        Route::post('updateMenu', [MenuController::class, 'updateMenu']);             // 更新菜单
        Route::post('addMenu', [MenuController::class, 'addMenu']);                   // 添加菜单
        Route::post('deleteMenu', [MenuController::class, 'deleteMenu']);             // 删除菜单
        Route::post('addMenuAuthority', [MenuController::class, 'addMenuAuthority']); // 添加角色菜单

        Route::get('getMenu', [MenuController::class, 'getMenu']);                             // 当前登录用户的菜单
        Route::get('getMenuTree', [MenuController::class, 'getMenuTree']);                     // 权限配置：菜单树
        Route::get('getMenuList', [MenuController::class, 'getMenuList']);                     // 菜单管理列表：获取菜单列表
        Route::get('getMenuById', [MenuController::class, 'getMenuById']);                     // 根据id获取菜单
        Route::get('getMenusByAuthorityId', [MenuController::class, 'getMenusByAuthorityId']); // 获取指定角色menu
    });

    // 角色
    Route::group(['prefix' => 'authority', 'middleware' => 'adminAuth'], function () {
        Route::post('createAuthority', [AuthorityController::class, 'createAuthority']); // 创建角色
        Route::post('updateAuthority', [AuthorityController::class, 'updateAuthority']); // 更新角色
        Route::post('deleteAuthority', [AuthorityController::class, 'deleteAuthority']); // 删除角色
        Route::get('authorityList', [AuthorityController::class, 'authorityList']);      // 角色列表
    });

    // 接口
    Route::group(['prefix' => 'api', 'middleware' => 'adminAuth'], function () {
        Route::post('createApi', [ApiController::class, 'createApi']);                   // 创建API
        Route::post('deleteApi', [ApiController::class, 'deleteApi']);                   // 删除API
        Route::post('updateApi', [ApiController::class, 'updateApi']);                   // 更新API
        Route::post('updateAuthorityApi', [ApiController::class, 'updateAuthorityApi']); // 更新角色API
        ROute::post('deleteApisByIds', [ApiController::class, 'deleteApisByIds']);       // 批量删除

        Route::get('getApiList', [ApiController::class, 'getApiList']);                                 // 获取api列表
        Route::get('allApiList', [ApiController::class, 'allApiList']);                                 // 获取所有api列表
        Route::get('getPolicyPathByAuthorityId', [ApiController::class, 'getPolicyPathByAuthorityId']); // 获取权限列表
        Route::get('detail', [ApiController::class, 'detail']);                                         // api详情
    });

    // 用户
    Route::group(['prefix' => 'user', 'middleware' => 'adminAuth'], function () {
        Route::post('createUser', [AdminUserController::class, 'createUser']);                 // 创建用户
        Route::post('setUserInfo', [AdminUserController::class, 'setUserInfo']);               // 设置用户信息
        Route::post('setUserAuthorities', [AdminUserController::class, 'setUserAuthorities']); // 设置用户角色
        Route::post('resetPassword', [AdminUserController::class, 'resetPassword']);           // 重置密码
        Route::post('deleteUser', [AdminUserController::class, 'deleteUser']);                 // 删除用户
        Route::post('setUserAuthority', [AdminUserController::class, 'setUserAuthority']);     // 设置用户角色
        Route::get('userList', [AdminUserController::class, 'userList']);                      // 用户列表
    });
});


// 用户管理
Route::group(['prefix' => 'user', 'namespace' => 'User', 'middleware' => 'adminAuth'], function () {
    Route::get('/list', [UserController::class, 'list']);             // 用户列表
    Route::get('/inviteList', [UserController::class, 'inviteList']); // 邀请用户列表
});


// 牧场管理
Route::group(['prefix' => 'ranch', 'namespace' => 'Ranch', 'middleware' => 'adminAuth'], function () {

    // 申请管理
    Route::group(['prefix' => 'apply'], function () {
        Route::get('list', [ApplyController::class, 'list']);     // 申请列表
        Route::get('detail', [ApplyController::class, 'detail']); // 申请详情
        Route::post('apply', [ApplyController::class, 'apply']);  // 操作审核
    });

    // 牧场管理
    Route::group(['prefix' => 'ranch'], function () {
        Route::get('list', [RanchController::class, 'list']);          // 牧场列表
        Route::get('/passList', [RanchController::class, 'passList']); // 已审核通过牧场列表
    });

});

// 认养管理
Route::group(['prefix' => 'sponsor', 'namespace' => 'Sponsor', 'middleware' => 'adminAuth'], function () {

    // 分类管理
    Route::group(['prefix' => 'category'], function () {
        Route::get('list', [SponsorCategoryController::class, 'list']);      // 分类列表

        Route::post('create', [SponsorCategoryController::class, 'create']); // 创建分类
        Route::post('update', [SponsorCategoryController::class, 'update']); // 更新分类
        Route::post('delete', [SponsorCategoryController::class, 'delete']); // 删除分类
    });

    // 认养商品管理
    Route::group(['prefix' => 'sponsorGoods'], function () {
        Route::get('list', [SponsorGoodsController::class, 'list']);     // 认养商品列表
        Route::get('detail', [SponsorGoodsController::class, 'detail']); // 认养商品详情

        Route::post('create', [SponsorGoodsController::class, 'create']);       // 创建认养商品
        Route::post('update', [SponsorGoodsController::class, 'update']);       // 更新认养商品
        Route::post('delete', [SponsorGoodsController::class, 'delete']);       // 删除认养商品
        Route::post('release', [SponsorGoodsController::class, 'release']);     // 商品上下架
        Route::post('recommend', [SponsorGoodsController::class, 'recommend']); // 商品推荐
    });

    // 认养管理
    Route::group(['prefix' => 'sponsor'], function () {
        Route::get('list', [SponsorController::class, 'list']);                                                   // 认养列表
        Route::get('integral/list', [UserIntegralController::class, 'list']);                                     // 发放积分记录列表

        Route::post('grantIntegral', [SponsorController::class, 'grantIntegral']);         // 发放积分
        Route::post('bindRanch', [SponsorController::class, 'bindRanch']);                 // 绑定牧场
    });

    // 宰杀管理
    Route::group(['prefix' => 'slaughter'], function () {
        Route::get('list', [SlaughterController::class, 'list']);               // 宰杀申请列表
        Route::get('detail', [SlaughterController::class, 'detail']);           // 宰杀申请详情
        Route::get('express/company/list', [ExpressController::class, 'list']); // 物流公司列表


        Route::post('examine', [SlaughterController::class, 'examine']);             // 审批
        Route::post('sendBack', [SlaughterController::class, 'sendBack']);           // 宰杀寄回
        Route::post('grantIntegral', [SlaughterController::class, 'grantIntegral']); // 发放积分
    });

});

// 商品管理
Route::group(['prefix' => 'goods', 'namespace' => 'Goods', 'middleware' => 'adminAuth'], function () {

    // 商品管理
    Route::group(['prefix' => 'goods'], function () {
        Route::get('list', [GoodsController::class, 'list']);     // 商品列表
        Route::get('detail', [GoodsController::class, 'detail']); // 商品详情

        Route::post('create', [GoodsController::class, 'create']);       // 创建商品
        Route::post('update', [GoodsController::class, 'update']);       // 更新商品
        Route::post('delete', [GoodsController::class, 'delete']);       // 删除商品
        Route::post('release', [GoodsController::class, 'release']);     // 商品上架/下架
        Route::post('recommend', [GoodsController::class, 'recommend']); // 商品推荐/取消推荐
    });

    // 分类管理
    Route::group(['prefix' => 'category'], function () {
        Route::get('list', [ShopCategoryController::class, 'list']);     // 分类列表
        Route::get('detail', [ShopCategoryController::class, 'detail']); // 分类详情

        Route::post('create', [ShopCategoryController::class, 'create']); // 创建分类
        Route::post('update', [ShopCategoryController::class, 'update']); // 更新分类
        Route::post('delete', [ShopCategoryController::class, 'delete']); // 删除分类
    });
});

// 订单管理
Route::group(['prefix' => 'order', 'namespace' => 'Order', 'middleware' => 'adminAuth'], function () {

    // 认养订单管理
    Route::group(['prefix' => 'sponsor'], function () {
        Route::get('list', [SponsorOrderController::class, 'list']);      // 认养订单列表
        Route::get('detail', [SponsorOrderController::class, 'detail']);  // 认养订单详情
        Route::post('update', [SponsorOrderController::class, 'update']); // 更新订单状态
    });

    // 商品订单管理
    Route::group(['prefix' => 'shop'], function () {
        Route::get('list', [ShopOrderController::class, 'list']);                                       // 商品订单列表
        Route::get('detail', [ShopOrderController::class, 'detail']);                                   // 商品订单详情

        Route::post('update', [ShopOrderController::class, 'update']);           // 更新订单状态
        Route::post('delivery', [ShopOrderController::class, 'delivery']);       // 操作发货
    });
});

// 其他
Route::group(['prefix' => 'other', 'namespace' => 'Other'], function () {

    // 阿里云cloud
    Route::group(['prefix' => 'aliYunCloud'], function () {
        Route::get('getTemporaryVouchers', [AliYunCloudController::class, 'getTemporaryVouchers']); // 获取临时凭证
    });
    Route::group(['prefix' => 'express'], function () {
        Route::get('info', [\App\Http\Controllers\Admin\Other\ExpressController::class, 'info']);                         // 物流信息
    });

    // 配置信息
    Route::group(['prefix' => 'setting'], function () {
        Route::get('list', [SettingController::class, 'list']);      // 配置信息
        Route::post('update', [SettingController::class, 'update']); // 更新配置
    });
});

// 公告消息
Route::group(['prefix' => 'message', 'namespace' => 'Message', 'middleware' => 'adminAuth'], function () {

    Route::get('list', [MessageController::class, 'list']);     // 公告消息列表
    Route::get('detail', [MessageController::class, 'detail']); // 公告消息详情

    Route::post('create', [MessageController::class, 'create']);   // 创建消息
    Route::post('update', [MessageController::class, 'update']);   // 更新消息
    Route::post('delete', [MessageController::class, 'delete']);   // 删除消息
    Route::post('release', [MessageController::class, 'release']); // 上架/下架
});
